$(function() {
	
	$('#orderdate').daterangepicker({
		 "showDropdowns": true,
		    "showWeekNumbers": true,
		    "showCustomRangeLabel": false,
		locale : {
            format: 'YYYY-MM-DD HH:mm:ss',
            separator : ' - ',
        	customRangeLabel : '自定义',
            applyLabel : '确定',
            cancelLabel : '取消',
            fromLabel : '起始时间',
            toLabel : '结束时间',
            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
            firstDay : 1,
            startDate: moment().startOf('day'),
            endDate: moment().endOf('day')
        }
	});
	
	// init date tables
	var storageTable = $("#storage_list").dataTable({
		"dom": '<"top"i>rt<"bottom"fp><"clear">',
		"deferRender": true,
		"processing" : true, 
	    "serverSide": true,
		"ajax": {
			url: base_url + "/outorder/orderList",
			type:"post",
	        data : function ( d ) {
	        	var obj = {};
	        	obj.orderid = $('#orderid').val();
	        	obj.customer = $('#customer').val();
	        	obj.contacts = $('#contacts').val();
	        	obj.orderdate = $('#orderdate').val();
	        	obj.typeb = 1;
	        	obj.typee = 3;
	        	obj.start = d.start;
	        	obj.length = d.length;
                return obj;
            }
	    },
	    "searching": false,
	    "ordering": false,
	   // "scrollX": true,	// X轴滚动条，取消自适应
	    "columns": [
	                { "data": 'to_inorout', "bSortable": false, "visible" : false},
	                { "data": 'to_orderid', "visible" : true,"width":'10%'},
	                { "data": 'to_customername', "visible" : true,"width":'10%'},
	                { "data": 'to_contacts', "visible" : true,"width":'10%'},
	                { "data": 'to_telephone', "visible" : true,"width":'10%'},
	                { "data": 'to_address', "visible" : true,"width":'10%'},
	                { "data": 'to_warehouse', "visible" : true,"width":'10%'},
	                { 
	                	"data": 'to_ordertime', 
	                	"visible" : true, 
	                	"width":'13%',
	                	"render": function ( data, type, row ) {
	                		return data?moment(new Date(data)).format("YYYY-MM-DD HH:mm:ss"):"";
	                	}
	                },
	                { "data": 'to_totalprice', "visible" : true,"width":'10%'},
	                { "data": 'to_remark', "visible" : true,"width":'10%'},
	                {
						"data": '操作' ,
						"width":'15%',
	                	"render": function ( data, type, row ) {
	                		return function(){
								var html = '<p id="'+ row.to_orderid +'" '+
									'>'+
									'<button class="btn btn-warning btn-xs getinfo" type="button">浏览</button>  '+
									'</p>';

	                			return html;
							};
	                	}
	                }
	            ],
		"language" : {
			"sProcessing" : "处理中...",
			"sLengthMenu" : "每页 _MENU_ 条记录",
			"sZeroRecords" : "没有匹配结果",
			"sInfo" : "第 _PAGE_ 页 ( 总共 _PAGES_ 页，_TOTAL_ 条记录 )",
			"sInfoEmpty" : "无记录",
			"sInfoFiltered" : "(由 _MAX_ 项结果过滤)",
			"sInfoPostFix" : "",
			"sSearch" : "搜索:",
			"sUrl" : "",
			"sEmptyTable" : "表中数据为空",
			"sLoadingRecords" : "载入中...",
			"sInfoThousands" : ",",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "上页",
				"sNext" : "下页",
				"sLast" : "末页"
			},
			"oAria" : {
				"sSortAscending" : ": 以升序排列此列",
				"sSortDescending" : ": 以降序排列此列"
			}
		}
	});
	
	// 搜索按钮
	$('#searchBtn').on('click', function(){
		storageTable.fnDraw();
	});
	
	
	$("#storage_list").on('click', '.getinfo',function() {
		var orderid = $(this).parent().attr("id");
		window.location.href=base_url+"/outorder/orderinfo?orderid="+orderid+"&type=0";
	});
	
});
